using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ccr;

namespace TestConsole
{   
    class Ping
    {
        public Pinger Pinger { get; set; }
    }

    class Pong
    {
        public Ponger Ponger { get; set; }
    }

    [Autorun]
    class Pinger : Actor
    {
        [Handler]
        private void OnPong(Pong msg)
        {
            Console.WriteLine("Pong");
            System.Threading.Thread.Sleep(1000); // not use Sleep() in a real program
            msg.Ponger.Post( new Ping { Pinger = this } );
        }
    }

    [Autorun]
    class Ponger : Actor
    {
        [Handler]
        private void OnPing(Ping msg)
        {
            Console.WriteLine("Ping");
            System.Threading.Thread.Sleep(1000); // not use Sleep() in a real program
            msg.Pinger.Post( new Pong { Ponger = this } );
        }
    }

    class Program
    {   
        static void Main(string[] args)
        {
            using (Factory.Dispatcher)
            using (var pinger = new Pinger())
            using (var ponger = new Ponger())
            {
                pinger.Post(new Pong { Ponger = ponger });

                Console.ReadKey();
            }
        }
    }
}